﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ly.Model;

namespace Xiangmu
{
    public partial class addUser : System.Web.UI.Page
    {
        ly.Model.UserInfo usermodel = new UserInfo();
        ly.BLL.UserInfo user = new ly.BLL.UserInfo();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnnewss_Click(object sender, EventArgs e)
        {

            usermodel.UserName = txtname.Text.Trim();
            usermodel.Pasword = txtpwd.Text.Trim();
            usermodel.Type = ddlnewss.Text.Trim();
            usermodel.QQ = TextBox1.Text.Trim();
            usermodel.Email = TextBox2.Text.Trim();
            Boolean flag = user.Add(usermodel);
            if (flag)
            {
                //Session["username"] = txtName.Value.Trim();
                //Session["type"] = ddlrole.Text.Trim();
                Response.Write("<script>alert('新建用户成功');</script>");
                Response.Redirect("User.aspx");

            }
            else
            {
                Response.Write("<script>alert('新建用户错误，请核对后重新尝试');</script>");
            }

        }

        protected void btncheck_Click(object sender, EventArgs e)
        {
            string username = txtname.Text.Trim();
           bool flag = user.Exists(username);
           if (flag)
           {
               lblmsg.Text = "该用户名已经被注册，请换一个新的用户名";
               btnnewss.Enabled = false;

           }
           else
           {
               lblmsg.Text = "该用户名可以被注册，请填写其他信息";
               btnnewss.Enabled = true;
           }
        }
    }
}